
/**
 *
 * @author Xinchro
 */
import java.awt.event.*;
import java.awt.*;

public class InputReader implements KeyListener, MouseListener, MouseWheelListener {

    RSSFeed feed;
    int test;

    public InputReader(RSSFeed rssFeed) {
        this.feed = rssFeed;
        test = 0;
    }

    public void keyReleased(KeyEvent e) {
    }

    public void keyPressed(KeyEvent e) {
        switch (e.getKeyCode()) {
            case KeyEvent.VK_ESCAPE:
                System.exit(0);
                break;
            case KeyEvent.VK_SPACE:
                if (test == 0) {
                    feed.writeNews("http://feeds.gawker.com/lifehacker/full");
                    test = 1;
                    System.out.println("Lifehacker");
                } else if (test == 1) {
                    feed.writeNews("http://feeds.feedburner.com/nerfnow/full");
                    test = 2;
                    System.out.println("NerfNow");
                } else if (test == 2) {
                        feed.writeNews("http://www.guildwars2.com/en/rss.xml");
                    test = 0;
                    System.out.println("Guild Wars 2");
                }
                break;


        }
    }

    public void mouseExited(MouseEvent e) {
    }

    public void mouseEntered(MouseEvent e) {
    }

    public void mouseReleased(MouseEvent e) {
    }

    public void mousePressed(MouseEvent e) {
        switch (e.getButton()) {
            case MouseEvent.BUTTON1:
                System.out.println("Left click");
                break;
            case MouseEvent.BUTTON2:
                System.out.println("Middle click");
                break;
            case MouseEvent.BUTTON3:
                System.out.println("Right click");
                break;
            //case MouseEvent.MOUSE_WHEEL:
            //System.out.println("Wheel rotated");
            //break;
            //case MouseWheelEvent:
            //System.out.println("Wheel rotated");
            //break;
        }
    }

    public void mouseClicked(MouseEvent e) {
        if(e.getComponent().getName().equalsIgnoreCase("urllist")){
            feed.writeNews(feed.gui.list.getSelectedItem());
        }
    }

    public void keyTyped(KeyEvent e) {
    }
    int scrollSens = 5;
    public void mouseWheelMoved(MouseWheelEvent e) {
        switch (e.getWheelRotation()) {
            case 1:
                System.out.println("Scrolled down");
                feed.gui.scrollPane.getVerticalScrollBar().setValue(feed.gui.scrollPane.getVerticalScrollBar().getValue()+scrollSens);
                break;
            case -1:
                System.out.println("Scrolled up");
                feed.gui.scrollPane.getVerticalScrollBar().setValue(feed.gui.scrollPane.getVerticalScrollBar().getValue()-scrollSens);
                break;
        }   
    }
}
